package com.uenpay.im.ui.old.activity.publicnumber;

import com.uenpay.im.configuration.APIConfiguration;
import com.uenpay.im.entities.HttpInvokeResult;
import com.uenpay.im.invokeitems.BaseHttpInvokeItem;

import org.json.JSONException;
import org.json.JSONObject;


/**
 * @author SL
 * @created 2016-1-8 上午10:27:35
 * @copyRight http://www.qiyunxin.com
 * @function 公众号详情
 */
public class PublicNumberDetailInvokeItem extends BaseHttpInvokeItem {
	public class PublicNumberDetailInvokeItemResult extends HttpInvokeResult {
		public PublicNumEntity publicNumEntity = new PublicNumEntity();
	}

	public PublicNumberDetailInvokeItemResult getOutput() {
		return (PublicNumberDetailInvokeItemResult) GetResultObject();
	}

	/**
	 * 获取公众号详情
	 * 
	 * @param publicnoid
	 *            公众号id
	 * @param isByCustId
	 *            是否通过用户id类型获取公众号详情
	 */
	public PublicNumberDetailInvokeItem(String publicnoid, boolean isByCustId) {
		String url = "";
		if (isByCustId) {
			url = APIConfiguration.getBaseUrl()
					+ "PublicNo/PublicNo/publicNoDetailByCust?custid="
					+ publicnoid + "&" + APIConfiguration.getCustIdAndToken();
		} else {
			url = APIConfiguration.getBaseUrl()
					+ "PublicNo/PublicNo/publicNoDetail?publicnoid="
					+ publicnoid + "&" + APIConfiguration.getCustIdAndToken();
		}
		SetUrl(url);
	}

	@Override
	protected Object DeserializeResult(String responseBody) {
		PublicNumberDetailInvokeItemResult result = new PublicNumberDetailInvokeItemResult();
		JSONObject json = null;
		try {
			json = new JSONObject(responseBody);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		if (json == null) {
			return null;
		}
		result.status = json.optInt("status");
		result.msg = json.optString("msg");
		if (result.status != 0) {
			return result;
		}
		JSONObject jo = json.optJSONObject("data");
		if (jo != null) {
			result.publicNumEntity = DesPublicNumEntity.desPublicNumEntity(jo);
		}
		return result;
	}
}
